home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / diskproc / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  5.4 KB  |  208 lines

  1. /*
  2.  *   $RCSfile: main.c,v $  
  3.  *   $Revision: 1.2 $  
  4.  *   $Date: 1996/05/04 23:51:46 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38. #include "sysdefs.h"
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "trace.h"
  42. #include "trace_funcs.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "disk.h"
  51. #include "volume.h"
  52. #include "queues.h"
  53. #include "queue_consist.h"
  54. #include "disk_funcs.h"
  55. #include "diskproc_globals.h"
  56. #include "diskproc_intfuncs.h"
  57. #include "diskproc_extfuncs.h"
  58.  
  59. main (
  60.     int        argc,
  61.     char    **argv
  62. )
  63. {
  64.  
  65.  
  66.     /*
  67.      *    check to see that we have the right number of arguments
  68.      */
  69. #    define NARGS 10 
  70.  
  71.     if (argc != NARGS )    {
  72.         fprintf(stderr, "%d args on exec: expected %d\n", argc, NARGS);
  73.  
  74.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  75.     }
  76.  
  77.     /*
  78.      *    set the trace levels
  79.      */
  80.     initializeTrace();
  81.  
  82.     /*
  83.      * ARGV[1]    get the value of trace
  84.      */
  85.     TraceFlags = (int) strtol(argv[1], NULL, 16);
  86.     TRACE(TR_DISKRW, TR_LEVEL_1);
  87.  
  88.     initErrorCodes();
  89.  
  90.     TRACE(TR_DISKRW, TR_LEVEL_1);
  91.     catchSignals();
  92.  
  93.     TRACE(TR_DISKRW, TR_LEVEL_1);
  94.     /*
  95.      *    ARGV[2] get the shared memory id
  96.      */
  97.     ShmId = (int) strtol(argv[2], NULL, 16);
  98.     TRACE(TR_DISKRW, TR_LEVEL_1);
  99.     TRPRINT(TR_DISKRW, TR_LEVEL_1, ("shared memory id:%x", ShmId));
  100.  
  101.     
  102.     /*
  103.      *    attach the shared memory segment
  104.      */
  105.     if ((ShmAddress = shmat(ShmId, 0, 0)) == (char *) -1)    {
  106.  
  107.         SM_ERROR(TYPE_FATAL, errno);
  108.     }
  109.     TRPRINT(TR_INIT, TR_LEVEL_1, ("shared memory attached at:%x", ShmAddress));
  110.  
  111.     /*
  112.      *    get shared memory information
  113.      */
  114.     if (shmctl(ShmId, IPC_STAT, &Shmstruct) < 0)    {
  115.  
  116.         SM_ERROR(TYPE_FATAL, errno);
  117.     }
  118. #if defined(_AIX) || defined(hpux) || defined(sparc) || defined(linux)
  119.     TRPRINT(TR_DISKRW, TR_LEVEL_1, ("shared memory size:%d",
  120.         Shmstruct.shm_segsz));
  121.     TRPRINT(TR_DISKRW, TR_LEVEL_1, ("shared memory ref count:%d",
  122.         Shmstruct.shm_nattch));
  123. #else
  124.     TRPRINT(TR_DISKRW, TR_LEVEL_1, ("shared memory size:%d",
  125.         Shmstruct.sm_size));
  126.     TRPRINT(TR_DISKRW, TR_LEVEL_1, ("shared memory ref count:%d",
  127.         Shmstruct.sm_count));
  128. #endif
  129.  
  130.     /*
  131.      *    ARGV[3] get the number of the communications socket
  132.      */
  133.     Socket = (int) strtol(argv[3], NULL, 16);
  134.     TRPRINT(TR_DISKRW, TR_LEVEL_1, ("socket id:%d", Socket));
  135.  
  136.  
  137.     /* 
  138.      * ARGV[4] get the volume name
  139.      */
  140.     DiskName = argv[4];
  141.  
  142.     /* ARGV[5]
  143.      * Get the id for the semaphore list that
  144.      * we'll use to sync with the server when
  145.      * manipulating disk queues.
  146.      */
  147.     SemId = (int) strtol(argv[5], NULL, 16);
  148.     TRPRINT(TR_DISKRW, TR_LEVEL_1, ("sem id:%d", SemId));
  149.  
  150.     /* ARGV[6]
  151.      * Get the semaphore number within the semaphore list.
  152.      */
  153.     SemNum = (int) strtol(argv[6], NULL, 16);
  154.     TRPRINT(TR_DISKRW, TR_LEVEL_1, ("Disk #:%d", SemNum));
  155.  
  156.     {     
  157.         ShmOffset             offset;
  158.  
  159.         /*
  160.          * ARGV[7]  Find our queue pair.
  161.          */
  162.         offset = (ShmOffset) strtol(argv[7], NULL, 16);
  163.         TRPRINT(TR_DISKRW, TR_LEVEL_1, ("argv[7] is %s",argv[8]));
  164.         TRPRINT(TR_DISKRW, TR_LEVEL_1, ("queue offset #:%d", offset));
  165.         DiskQueue =   ShmOffsetToAddress(offset, QUEUEPAIR);
  166.  
  167.         /*
  168.          * ARGV[9] Find the semaphore for kicking the server.
  169.          */
  170.         offset = (ShmOffset) strtol(argv[8], NULL, 16);
  171.         TRPRINT(TR_DISKRW, TR_LEVEL_1, ("argv[8] is %s",argv[9]));
  172.         TRPRINT(TR_DISKRW, TR_LEVEL_1, ("Replies offset #:%d", offset));
  173.         Replies   =   ShmOffsetToAddress(offset, MUTEX);
  174.  
  175.         /* 
  176.          * ARGV[9] Get NumMsgBufs so that the queuing macros work.
  177.          * (NumMsgBufs is what's used for QUEUE_SIZE)
  178.          */
  179.         TRPRINT(TR_DISKRW, TR_LEVEL_1, ("argv[9] is %s",argv[10]));
  180.         NumMsgBufs = (int) strtol(argv[9], NULL, 16);
  181.         TRPRINT(TR_DISKRW, TR_LEVEL_1, ("NumMsgBufs :%d", NumMsgBufs));
  182.  
  183.         /*
  184.          * That's all folks!
  185.          * The elements stashed in the queues are offsets from ShmAddress,
  186.          * so we don't need to know where the msg buffers start
  187.          * and end or where the disk queues start & end.
  188.          */
  189.     }
  190.  
  191.     /* 
  192.      * get our parent's pid - we'll need it later to
  193.      * detect server death
  194.      */
  195.     if((Parent = getppid())<0) {
  196.         SM_ERROR(TYPE_FATAL, errno);
  197.     }
  198.     TRPRINT(TR_INIT, TR_LEVEL_1, ("Parent pid is %d", Parent));
  199.  
  200.     process_identity.me = DISK_PROC;
  201.     process_identity.other = (1-process_identity.me);
  202.  
  203.     /*
  204.      *    start the read loop
  205.      */
  206.     readDiskMessage();
  207. }
  208.